package com.lyl.syt.controller;/**
 * @author Mr.Luo
 * @date 2022-05-25 16:17
 */

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lyl.syt.common.result.Result;
import com.lyl.syt.enums.OrderStatusEnum;
import com.lyl.syt.model.order.OrderInfo;
import com.lyl.syt.service.OrderService;
import com.lyl.syt.vo.order.OrderQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @author Mr.Luo
 * @date 2022-05-25 16:17
 * @desc
 */
@Api(tags = "订单接口")
@RestController
@RequestMapping("/admin/order/orderInfo")
@RequiredArgsConstructor
public class OrderController {
    private final OrderService orderService;

    @GetMapping("/list/{page}/{limit}")
    public Result<IPage<OrderInfo>> list(@PathVariable Long page,
                                         @PathVariable Long limit,
                                         OrderQueryVo queryVo,
                                         HttpServletRequest request
    ) {
        Page<OrderInfo> pageParam = new Page<>(page, limit);
        IPage<OrderInfo> pageInfo = orderService.selectPage(pageParam, queryVo);
        return Result.ok(pageInfo);
    }

    @ApiOperation(value = "获取订单状态")
    @GetMapping("getStatusList")
    public Result getStatusList() {
        return Result.ok(OrderStatusEnum.getStatusList());
    }

    @ApiOperation(value = "获取订单")
    @GetMapping("show/{id}")
    public Result<Map<String,Object>> get(@ApiParam(name = "orderId", value = "订单id", required = true) @PathVariable Long id) {
        return Result.ok(orderService.show(id));
    }

}
